package com.example.demo.word;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;

public class CustomSheetWriterHandler implements SheetWriteHandler {

    private Integer sheetNo;

    private String sheetName;

    public CustomSheetWriterHandler() {
    }

    public CustomSheetWriterHandler(String sheetName) {
        this.sheetName = sheetName;
    }

    public CustomSheetWriterHandler(int sheetNo, String sheetName) {
        this.sheetNo = sheetNo;
        this.sheetName = sheetName;
    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        if (sheetNo == null) {
            sheetNo = 0;
        }
        writeWorkbookHolder.getCachedWorkbook().setSheetName(sheetNo, sheetName);
    }
}
